65. Introduction to Psake
65.1: Basic outline
| Task Rebuild -Depends Clean, Build {
"Rebuild"
}
Task Build {
"Build"
}
Task Clean {
"Clean"
}
|
| Task default -Depends Build
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 | # Will display task as:
# -------- Rebuild --------
# -------- Build --------
FormatTaskName "-------- {0} --------"
# will display tasks in yellow colour:
# Running Rebuild
FormatTaskName {
param($taskName)
"Running $taskName" - foregroundcolor yellow
}
Task Rebuild -Depends Clean, Build {
"Rebuild"
}
Task Build {
"Build"
}
|
| Task Clean {
"Clean"
}
Task default -Depends Build
|
65.3: Run Task conditionally
1
2
3
4
5
6
7
8
9
10
11
12
13
14 | propreties {
$isOk = $false
}
# By default the Build task won't run, unless there is a param $true
Task Build -precondition { return $isOk } {
"Build"
}
Task Clean {
"Clean"
}
Task default -Depends Build
|
65.4: ContinueOnError
| Task Build -depends Clean {
"Build"
}
Task Clean -ContinueOnError {
"Clean"
throw "throw on purpose, but the task will continue to run"
}
Task default -Depends Build
|